package al.xc.wxsession.controller.base;

import al.xc.common.exception.ResultCodeDefine;
import al.xc.wxsession.data.ResultVo;

/**
 * controller基类，通用方法定义
 */
public class BaseController {
    /**
     * 返回成功结果
     *
     * @param vl
     * @param <T>
     * @return
     */
    public <T> ResultVo<T> successResult(T vl) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(ResultCodeDefine.OK.getCode());
        result.setMsg("ok");
        result.setData(vl);
        return result;
    }

    /**
     * 通用失败返回
     *
     * @param errorInfo
     * @param vl
     * @param <T>
     * @return
     */
    public <T> ResultVo<T> failedResult(String errorInfo, T vl) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(ResultCodeDefine.FAIL.getCode());
        result.setMsg(errorInfo);
        result.setData(vl);
        return result;
    }
}
